public class HashBucket<K,V> {
    static class Node<K,V> {
        public K key;
        public V val;
        public Node<K,V> next;

        public Node (K key,V val) {
            this.key = key;
            this.val = val;
        }
    }
    public Node<K,V>[] array;
    public int userSize;
    static final float DEFAULT_FACTOR = 0.75f;

    public HashBucket() {
        this.array = (Node<K,V>[])new Node[10];
    }
    public void put(K key, V val) {
        int hash = Math.abs(key.hashCode());
        int index = hash % array.length;
        Node<K,V> cur = array[index];
        while(cur != null) {
            if(cur.equals(key) ) {
                //已经有了，更新value
                cur.val = val;
                return;
            }
            cur = cur.next;
        }
        //没有 进行尾差法
        Node<K,V> node = new Node<>(key,val);
        node.next = array[index];
        array[index] = node;
        userSize++;
    }
    public V getValue(K key) {
        int hash = Math.abs(key.hashCode());
        int index = hash % array.length;
        Node<K,V> cur = array[index];
        while(cur != null) {
            if(cur.key.equals(key) ) {
                //找到了，返回value
                return cur.val;
            }
            cur = cur.next;
        }
        return null;
    }
}
